var xmlHttpRequest;
function createXMLHttpRequest()
{
    if (window.XMLHttpRequest) //非IE浏览器
    {
        xmlHttpRequest = new XMLHttpRequest();
    }
    else if (window.ActiveObject)//IE6以上版本的IE浏览器
    {
        xmlHttpRequest = new ActiveObject("Msxml2.XMLHTTP");
    }
    else //IE6及以下版本IE浏览器
    {
        xmlHttpRequest = new ActiveObject("Microsoft.XMLHTTP");
    }
}

function usernameIsExist() {
    //var username = document.NewAccountForm.username.value;
    var username = document.getElementById('username').value;
    sendRequest("/account/usernameIsExist?username=" + username);
}

function sendRequest(url) {
    createXMLHttpRequest();
    xmlHttpRequest.open("GET", url, true);
    xmlHttpRequest.onreadystatechange = processResponse;
    xmlHttpRequest.send(null);
}

function processResponse() {
    if (xmlHttpRequest.readyState == 4) {
        if (xmlHttpRequest.status == 200) {
            var responseInfo = xmlHttpRequest.responseXML.getElementsByTagName("msg")[0].firstChild.data;

            var div1 = document.getElementById('usernameInfo');

            if (responseInfo == "Exist") {
                div1.innerHTML = "<font color='#FF6984'>用户名已存在</font>";
            } else if(responseInfo == "Null"){
                div1.innerHTML = "<font color='#FF6984'>用户名不能为空</font>";
            } else {
                div1.innerHTML = "<font color='#FEF9C'>用户名可用</font>";
            }
        }
    }
}


function passwordExit() {
    var value = document.getElementById("password").value;
    var passwordInfo = document.getElementById('passwordInfo');
    if(value.length <= 0) {
        passwordInfo.innerHTML = "<font color='#FF6984'>密码不能为空</font>";
        return false;
    } else {
        passwordInfo.innerHTML ="";
        return true;
    }
}


function checkPass() {
    var repeatedPassword = document.getElementById("repeatedPassword").value;
    var password = document.getElementById("password").value;
    var repeatedPasswordInfo = document.getElementById('repeatedPasswordInfo')
    if(repeatedPassword != password) {
        repeatedPasswordInfo.innerHTML = "<font color='#FF6984'>两次密码不一致</font>";
    }
    else{
        repeatedPasswordInfo.innerHTML = "";
    }
}

function firstNameExit() {
    var value = document.getElementById("firstName").value;
    var firstNameInfo = document.getElementById('firstNameInfo');
    if(value.length <= 0) {
        firstNameInfo.innerHTML = "<font color='#FF6984'>姓氏必填</font>";
        return false;
    } else {
        firstNameInfo.innerHTML ="";
        return true;
    }
}

function lastNameExit() {
    var value = document.getElementById("lastName").value;
    var lastNameInfo = document.getElementById('lastNameInfo');
    if(value.length <= 0) {
        lastNameInfo.innerHTML = "<font color='#FF6984'>名不能为空</font>";
        return false;
    } else {
        lastNameInfo.innerHTML ="";
        return true;
    }
}

function address1Exit() {
    var value = document.getElementById("address1").value;
    var address1Info = document.getElementById('address1Info');
    if(value.length <= 0) {
        address1Info.innerHTML = "<font color='#FF6984'>地址一必填</font>";
        return false;
    } else {
        address1Info.innerHTML ="";
        return true;
    }
}

function cityExit() {
    var value = document.getElementById("city").value;
    var cityInfo = document.getElementById('cityInfo');
    if(value.length <= 0) {
        cityInfo.innerHTML = "<font color='#FF6984'>城市必填</font>";
        return false;
    } else {
        cityInfo.innerHTML ="";
        return true;
    }
}

function stateExit() {
    var value = document.getElementById("city").value;
    var stateInfo = document.getElementById('stateInfo');
    if(value.length <= 0) {
        stateInfo.innerHTML = "<font color='#FF6984'>州必填</font>";
        return false;
    } else {
        stateInfo.innerHTML ="";
        return true;
    }
}

function zipExit() {
    var value = document.getElementById("zip").value;
    var zipInfo = document.getElementById('zipInfo');
    if(value.length <= 0) {
        zipInfo.innerHTML = "<font color='#FF6984'>邮编必填</font>";
        return false;
    } else {
        zipInfo.innerHTML ="";
        return true;
    }
}

function countryExit() {
    var value = document.getElementById("country").value;
    var countryInfo = document.getElementById('countryInfo');
    if(value.length <= 0) {
        countryInfo.innerHTML = "<font color='#FF6984'>国家必填</font>";
        return false;
    } else {
        countryInfo.innerHTML ="";
        return true;
    }
}